
//Flash文件上传组件JS辅助类(FILEUPLOAD)
function FU(){};

//上传组件用户配置参数数组
FU.uploadParameterArray=[];

/*上传文件有效性判断*/
FU.checkAndUpload=function(id,serverJsonData){
	var serverJson= eval("(" + serverJsonData + ")");
	//获取参数
	var parameters=FU.uploadParameterArray[id];
	//优先调用扩展的方法
	if(parameters.checkAndUploadExtend){
		parameters.checkAndUploadExtend(id,serverJson);	
	}else{
		//默认有效性判断
		if(serverJson.checkType=="all"){
			//各种校验通过
			
		}else if(serverJson.checkType=="suffix"){
			//文件后缀名有误
			alert("文件后缀名有误");
		}else if(serverJson.checkType=="noSuffix"){
			//不允许的后缀名出错
			alert("不允许的后缀名有误");
		}else if(serverJson.checkType=="size"){
			//文件大小有误
			alert("文件大小有误");
		}
	}
}

/*文件上传进度控制*/
FU.uploadOnProgress=function(id,serverJsonData){
	var serverJson= eval("(" + serverJsonData + ")");
	//获取参数
	var parameters=FU.uploadParameterArray[id];
	//调用扩展的方法
	if(parameters.uploadOnProgressExtend){
		parameters.uploadOnProgressExtend(id,serverJson);	
	}
}

/*文件上传成功后，将服务器返回值返回到页面*/
FU.uploadComplete=function(id,serverData){
	//获取参数
	var parameters=FU.uploadParameterArray[id];
	if(parameters.uploadCompleteExtend){
		parameters.uploadCompleteExtend(id,serverData);	
	}
}

/*
 * 初始化Flash上传组件 
*/
FU.iniFlashPlayer=function(iniDataJson){ 
	//默认参数
	var setting={
			id:"FileUpload",
			swfPath:"<%=path%>/FileUploadHR/FileUploadForHr.swf",
			serverPath:"<%=path%>/servlet/FileUploadManagerServlet",
			width:128,
			height:128,
			fileSize:"1"
	};
	//自定义参数赋值
	for (items in iniDataJson){
		setting[items]=iniDataJson[items];
	}
	//参数保存
	FU.uploadParameterArray[setting.id]=setting;
	document.write(' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.write(' id="'+setting.id+'" width="'+setting.width+'" height="'+setting.height+'"');
	document.write(' codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">');
	document.write(' <param name="movie" value="'+setting.swfPath+'" />');
	document.write(' <param name="quality" value="high" />');
	document.write(' <param name="allowScriptAccess" value="always" />');
	document.write(' <param NAME=wmode value=transparent>');
	document.write(' <param name="FlashVars" value="id='+setting.id+'">');
	document.write(' <embed src="'+setting.swfPath+'" FlashVars="id='+setting.id+'"');
	document.write(' quality="high" width="'+setting.width+'" wmode="transparent" height="'+setting.height+'" name="'+setting.id+'"');
	document.write(' play="true" quality="high" allowScriptAccess="always"');
	document.write(' type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>');
	document.write(' </object>');
}

//Flash初始化参数 FOR Flash
FU.iniFlashSetting=function(id){
	return FU.uploadParameterArray[id];
}

//Flash初始化参数 FOR YOU
FU.getSettingById=function(id){
	return FU.uploadParameterArray[id];	
}


//json对象转字符串形式
FU.jsonToStr=function(o) {
	var arr = [];
	var fmt = function(s) {
		if (typeof s == 'object' && s != null) return json2str(s);
		return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s;
	}
	for (var i in o) arr.push("'" + i + "':" + fmt(o[i]));
	return '{' + arr.join(',') + '}';
}



